
//类模板对象做函数参数
//1-指定类型传递，在函数接口部分就指定了传入的对象的成员和对象所属的类是什么类型
#include <iostream>
#include <cstring>
using namespace std;

template <class T1, class T2>
class person
{
public:
    T1 age;

    T2 name;

    person(T1 m_age, T2 m_name) : age(m_age), name(m_name) {}

    void show_type()
    {
        cout << "T1的参数类型是" << typeid(T1).name() << endl;
        cout << "T2的参数类型是" << typeid(T2).name() << endl;
    }
};

void test(person<int, string> &m_pp)
{

    cout << m_pp.age << m_pp.name << endl;
}

int main()
{
    person<int, string> pp(23, "xiao_bai");
    test(pp);
    pp.show_type();
}

//2 参数模板化//  先把数据类型参数化  然后再把参数模板化
#include <iostream>
#include <cstring>
using namespace std;

template <class T1, class T2>
class person
{
public:
    T1 age;

    T2 name;

    person(T1 m_age, T2 m_name) : age(m_age), name(m_name) {}

    void show_type()
    {
        cout << "T1的参数类型是" << typeid(T1).name() << endl;
        cout << "T2的参数类型是" << typeid(T2).name() << endl;
    }
};

template <class T1, class T2>
void test(person<T1, T2> &m_pp)
{

    cout << m_pp.age << m_pp.name << endl;
}

int main()
{
    person<int, string> pp(23, "xiao_bai");
    test(pp);
    pp.show_type();
}

//3-整个类模板化
#include <iostream>
#include <cstring>
using namespace std;

template <class T1, class T2>
class person
{
public:
    T1 age;

    T2 name;

    person(T1 m_age, T2 m_name) : age(m_age), name(m_name) {}

    void show_type()
    {
        cout << "T1的参数类型是" << typeid(T1).name() << endl;
        cout << "T2的参数类型是" << typeid(T2).name() << endl;
    }
};

template <class T1, class T2>
void test(T &m_pp) //整个类模板化
{

    cout << m_pp.age << m_pp.name << endl;
}

int main()
{
    person<int, string> pp(23, "xiao_bai");
    test(pp);
    pp.show_type();
}
